#include <butil/string_printf.h>
#include <gflags/gflags.h>

#include "index/deletion_index/deletion_index_indexer.h"
#include "file_system/file_writer/normal_file_writer.h"

namespace hawking {
namespace indexlib {

DEFINE_int32(deletion_index_hashset_bytes, 1024, "hashset init bytes");

Status DeletionMapIndexer::Init() {
    delete_set_.reset(new HashSet<DocId>(FLAGS_deletion_index_hashset_bytes));
    return Status::OK;
}

void DeletionMapIndexer::Filter(SegmentContext* segment_ctx) const {
    const std::vector<DocId>& doc_ids = segment_ctx->DocIds();
    std::vector<DocContext>& doc_ctxs = *(segment_ctx->MutableDocContext());
    for (size_t idx = 0; idx < doc_ids.size(); ++idx) {
        DocContext& doc_ctx = doc_ctxs[idx];
        if (doc_ctx.filtered) {
            continue;
        }

        if (IsDeleted(doc_ids[idx])) {
            doc_ctx.filtered = true;
            segment_ctx->DecrRelateCount();
        }
    }
}

}
}